package com.ssyu.examination.exam.service;

import java.util.ArrayList;
import java.util.List;

import com.ssyu.examination.conmmon.PageModel;
import com.ssyu.examination.conmmon.util.DBUtil;
import com.ssyu.examination.exam.entity.ExamPlanEntity;

public class ExamsService {

	/**
	 * 查询考试
	 */
	public PageModel<ExamPlanEntity> ListExam(int page, int rows) {
		StringBuffer sb = new StringBuffer();
		List<Object> objects = new ArrayList<Object>();
		sb.append("SELECT exam_plan.exam_time_start, exam_plan.exam_time_stop, exam_plan.exam_classroom, qes_exam_paper.`name` AS qes_exam_paper__name, ");
		sb.append("sys_class.`name` AS sys_class__name, exam_plan.operate_user_id, sys_user.`name` AS sys_user__name, exam_plan.operate_time ,   ");
		sb.append("exam_plan.id,exam_plan.exam_paper_id,exam_plan.to_user_ids,exam_plan.to_class_id FROM exam_plan ");
		sb.append("LEFT JOIN qes_exam_paper ON exam_plan.exam_paper_id = qes_exam_paper.id  ");
		sb.append("LEFT JOIN sys_class ON exam_plan.to_class_id = sys_class.id ");
		sb.append("LEFT JOIN sys_user ON exam_plan.to_user_ids = sys_user.id ");
		sb.append("WHERE exam_plan.exam_time_start > now() ORDER BY exam_plan.exam_time_start ASC LIMIT ?,? ");
		objects.add((page - 1) * rows);
		objects.add(rows);
		return DBUtil.executeQueryByPage(ExamPlanEntity.class, sb.toString(),
				objects);
	}

}
